package com.example.bms.serviceimpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.bms.entity.Teacher;
import com.example.bms.mapper.TeacherMapper;
import com.example.bms.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


/**
 * @apiNote 教师的增删改查
 * @author
 * @email 1627856348@qq.com
 * @since 1.0.0
 */
@Service
@Transactional
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;


    /**
     * @apiNote 查询所有教师
     * @param page 页数
     * @author
     * @email 1627856348@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public IPage<Teacher> findAll(Page<Teacher> page) {
        return teacherMapper.findAllPage(page);
    }


    /**
     * @apiNote 查询所有教师
     * @author
     * @email 1627856348@qq.com
     * @return IPage<Teacher>
     * @since 1.0.0
     */
    @Override
    public List<Teacher> findAll() {
        return teacherMapper.findAll();
    }


    /**
     * @apiNote 根据teacherId查询某一教师所有信息
     * @author
     * @param teacherId 教师id
     * @email 1627856348@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @Override
    public Teacher findById(Integer teacherId) {
        return teacherMapper.findById(teacherId);
    }


    /**
     * @apiNote 根据教师id删除对应老师
     * @author
     * @param teacherId 教师id
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Override
    public int deleteById(Integer teacherId) {
        return teacherMapper.deleteById(teacherId);
    }


    /**
     * @apiNote 根据教师id修改对应老师信息
     * @param teacher
     * @author  教师实体类
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Override
    public int update(Teacher teacher) {
        return teacherMapper.update(teacher);
    }


    /**
     * @apiNote 增加老师
     * @author
     * @param teacher 教师实体类
     * @email 1627856348@qq.com
     * @return int类型，受影响的条数
     * @since 1.0.0
     */
    @Override
    public int add(Teacher teacher) {
        return teacherMapper.add(teacher);
    }
}
